package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingRes;
import com.ruoyi.teaching.service.ITeachingResService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/res")
public class TeachingResController extends BaseController
{
    @Autowired
    private ITeachingResService teachingResService;

    /**
     * 查询资源信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:res:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingRes teachingRes)
    {
        startPage();
        List<TeachingRes> list = teachingResService.selectTeachingResList(teachingRes);
        return getDataTable(list);
    }

    /**
     * 导出资源信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:res:export')")
    @Log(title = "资源信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingRes teachingRes)
    {
        List<TeachingRes> list = teachingResService.selectTeachingResList(teachingRes);
        ExcelUtil<TeachingRes> util = new ExcelUtil<TeachingRes>(TeachingRes.class);
        util.exportExcel(response, list, "资源信息数据");
    }

    /**
     * 获取资源信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:res:query')")
    @GetMapping(value = "/{resourcesId}")
    public AjaxResult getInfo(@PathVariable("resourcesId") Long resourcesId)
    {
        return AjaxResult.success(teachingResService.selectTeachingResByResourcesId(resourcesId));
    }

    /**
     * 新增资源信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:res:add')")
    @Log(title = "资源信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingRes teachingRes)
    {
        return toAjax(teachingResService.insertTeachingRes(teachingRes));
    }

    /**
     * 修改资源信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:res:edit')")
    @Log(title = "资源信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingRes teachingRes)
    {
        return toAjax(teachingResService.updateTeachingRes(teachingRes));
    }

    /**
     * 删除资源信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:res:remove')")
    @Log(title = "资源信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{resourcesIds}")
    public AjaxResult remove(@PathVariable Long[] resourcesIds)
    {
        return toAjax(teachingResService.deleteTeachingResByResourcesIds(resourcesIds));
    }
}
